
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>5.6 压缩纹理 · 游戏引擎浅入浅出</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="captainchen">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-lightbox/css/lightbox.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="5.7 图片压缩工具.html" />
    
    
    <link rel="prev" href="5.5 绘制带贴图的立方体盒子.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">目录</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../前言.html">
            
                <a href="../前言.html">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../1. 游戏引擎框架介绍/1. 游戏引擎框架介绍.html">
            
                <a href="../1. 游戏引擎框架介绍/1. 游戏引擎框架介绍.html">
            
                    
                    1. 游戏引擎框架介绍
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../1. 游戏引擎框架介绍/1.1 暗中观察unity.html">
            
                <a href="../1. 游戏引擎框架介绍/1.1 暗中观察unity.html">
            
                    
                    1.1 暗中观察unity
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.2" data-path="../1. 游戏引擎框架介绍/1.2 游戏引擎组成.html">
            
                <a href="../1. 游戏引擎框架介绍/1.2 游戏引擎组成.html">
            
                    
                    1.2 游戏引擎组成
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../2. Opengl开发环境搭建/2. Opengl开发环境搭建.html">
            
                <a href="../2. Opengl开发环境搭建/2. Opengl开发环境搭建.html">
            
                    
                    2. Opengl开发环境搭建
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="../2. Opengl开发环境搭建/2.1 Opengl到底是什么.html">
            
                <a href="../2. Opengl开发环境搭建/2.1 Opengl到底是什么.html">
            
                    
                    2.1 Opengl到底是什么
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="../2. Opengl开发环境搭建/2.2 搭建Opengl开发环境.html">
            
                <a href="../2. Opengl开发环境搭建/2.2 搭建Opengl开发环境.html">
            
                    
                    2.2 搭建Opengl开发环境
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../3. 绘制简单图形/3. 绘制简单图形.html">
            
                <a href="../3. 绘制简单图形/3. 绘制简单图形.html">
            
                    
                    3. 绘制简单图形
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../3. 绘制简单图形/3.1 画个三角形.html">
            
                <a href="../3. 绘制简单图形/3.1 画个三角形.html">
            
                    
                    3.1 画个三角形
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="../3. 绘制简单图形/3.2 画个正方形.html">
            
                <a href="../3. 绘制简单图形/3.2 画个正方形.html">
            
                    
                    3.2 画个正方形
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="../3. 绘制简单图形/3.3 画个立方体.html">
            
                <a href="../3. 绘制简单图形/3.3 画个立方体.html">
            
                    
                    3.3 画个立方体
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../4. 着色器/4. 着色器.html">
            
                <a href="../4. 着色器/4. 着色器.html">
            
                    
                    4. 着色器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="../4. 着色器/4.1 着色器是什么.html">
            
                <a href="../4. 着色器/4.1 着色器是什么.html">
            
                    
                    4.1 着色器是什么
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.2" data-path="../4. 着色器/4.2 Unity Shader和OpenGL Shader.html">
            
                <a href="../4. 着色器/4.2 Unity Shader和OpenGL Shader.html">
            
                    
                    4.2 Unity Shader和OpenGL Shader
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.3" data-path="../4. 着色器/4.3 顶点着色器.html">
            
                <a href="../4. 着色器/4.3 顶点着色器.html">
            
                    
                    4.3 顶点着色器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.4" data-path="../4. 着色器/4.4 片段着色器.html">
            
                <a href="../4. 着色器/4.4 片段着色器.html">
            
                    
                    4.4 片段着色器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="5. 绘制贴图.html">
            
                <a href="5. 绘制贴图.html">
            
                    
                    5. 绘制贴图
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="5.1 颜色和贴图.html">
            
                <a href="5.1 颜色和贴图.html">
            
                    
                    5.1 颜色和贴图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="5.2 贴图文件介绍.html">
            
                <a href="5.2 贴图文件介绍.html">
            
                    
                    5.2 贴图文件介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="5.3 CPU与GPU的通信方式.html">
            
                <a href="5.3 CPU与GPU的通信方式.html">
            
                    
                    5.3 CPU与GPU的通信方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.4" data-path="5.4 使用stb_image解析图片.html">
            
                <a href="5.4 使用stb_image解析图片.html">
            
                    
                    5.4 使用stb_image解析图片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.5" data-path="5.5 绘制带贴图的立方体盒子.html">
            
                <a href="5.5 绘制带贴图的立方体盒子.html">
            
                    
                    5.5 绘制带贴图的立方体盒子
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.6.6" data-path="5.6 压缩纹理.html">
            
                <a href="5.6 压缩纹理.html">
            
                    
                    5.6 压缩纹理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.7" data-path="5.7 图片压缩工具.html">
            
                <a href="5.7 图片压缩工具.html">
            
                    
                    5.7 图片压缩工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.8" data-path="5.8 使用压缩纹理.html">
            
                <a href="5.8 使用压缩纹理.html">
            
                    
                    5.8 使用压缩纹理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="../6. 索引与缓冲区对象/6. 缓冲区对象.html">
            
                <a href="../6. 索引与缓冲区对象/6. 缓冲区对象.html">
            
                    
                    6. 缓冲区对象
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.7.1" data-path="../6. 索引与缓冲区对象/6.1 顶点索引.html">
            
                <a href="../6. 索引与缓冲区对象/6.1 顶点索引.html">
            
                    
                    6.1 顶点索引
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.2" data-path="../6. 索引与缓冲区对象/6.2 缓冲区对象.html">
            
                <a href="../6. 索引与缓冲区对象/6.2 缓冲区对象.html">
            
                    
                    6.2 缓冲区对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="../7. Mesh和材质/7. Mesh和材质.html">
            
                <a href="../7. Mesh和材质/7. Mesh和材质.html">
            
                    
                    7. Mesh和材质
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.8.1" data-path="../7. Mesh和材质/7.1 导出Mesh文件.html">
            
                <a href="../7. Mesh和材质/7.1 导出Mesh文件.html">
            
                    
                    7.1 导出Mesh文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8.2" data-path="../7. Mesh和材质/7.2 使用Mesh文件.html">
            
                <a href="../7. Mesh和材质/7.2 使用Mesh文件.html">
            
                    
                    7.2 使用Mesh文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8.3" data-path="../7. Mesh和材质/7.3 Shader文件创建与使用.html">
            
                <a href="../7. Mesh和材质/7.3 Shader文件创建与使用.html">
            
                    
                    7.3 Shader文件创建与使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >5.6 压缩纹理</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <html><head></head><body><div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><ul><li><span class="title-icon "></span><a href="#56-&#x538B;&#x7F29;&#x7EB9;&#x7406;"><b></b>5.6 &#x538B;&#x7F29;&#x7EB9;&#x7406;</a></li><ul><li><span class="title-icon "></span><a href="#1-&#x4E3A;&#x4EC0;&#x4E48;&#x4F7F;&#x7528;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#xFF1F;"><b></b>1. &#x4E3A;&#x4EC0;&#x4E48;&#x4F7F;&#x7528;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#xFF1F;</a></li><li><span class="title-icon "></span><a href="#2-&#x4F7F;&#x7528;&#x538B;&#x7F29;&#x7EB9;&#x7406;"><b></b>2. &#x4F7F;&#x7528;&#x538B;&#x7F29;&#x7EB9;&#x7406;</a></li><li><span class="title-icon "></span><a href="#3-&#x67E5;&#x770B;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#x6548;&#x679C;"><b></b>3. &#x67E5;&#x770B;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#x6548;&#x679C;</a></li><li><span class="title-icon "></span><a href="#4-&#x95EE;&#x9898;&#x4E0E;&#x4F18;&#x5316;"><b></b>4. &#x95EE;&#x9898;&#x4E0E;&#x4F18;&#x5316;</a></li></ul></ul></ul></div><h2 id="56-&#x538B;&#x7F29;&#x7EB9;&#x7406;"><a name="56-&#x538B;&#x7F29;&#x7EB9;&#x7406;" class="anchor-navigation-ex-anchor" href="#56-&#x538B;&#x7F29;&#x7EB9;&#x7406;"><i class="fa fa-link" aria-hidden="true"></i></a>5.6 &#x538B;&#x7F29;&#x7EB9;&#x7406;</h2>
<pre><code>CLion&#x9879;&#x76EE;&#x6587;&#x4EF6;&#x4F4D;&#x4E8E; samples\texture\draw_cube_texture_compress
</code></pre><p>&#x4E0A;&#x4E00;&#x8282;&#x89E3;&#x6790;&#x4E86; <code>urban.jpg</code> &#x8FD9;&#x4E2A;&#x56FE;&#x7247;&#xFF0C;&#x4ECE;&#x4E2D;&#x62FF;&#x5230;RGB&#x6570;&#x636E;&#xFF0C;&#x4E0A;&#x4F20;&#x5230;GPU&#xFF0C;&#x8FDB;&#x884C;&#x6E32;&#x67D3;&#x3002;
&#x4E0A;&#x4F20;RGB&#x6570;&#x636E;&#x5230;GPU&#xFF0C;&#x4F7F;&#x7528;&#x4E86;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-c++"><span class="hljs-comment">//3. &#x5C06;&#x56FE;&#x7247;rgb&#x6570;&#x636E;&#x4E0A;&#x4F20;&#x5230;GPU;</span>
glTexImage2D(GL_TEXTURE_2D, <span class="hljs-number">0</span>, GL_RGB, texture2d-&gt;width_, texture2d-&gt;height_, <span class="hljs-number">0</span>, texture2d-&gt;gl_texture_format_, GL_UNSIGNED_BYTE, data);
</code></pre>
<p>&#x63A5;&#x53E3;&#x5B9A;&#x4E49;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-c++"><span class="hljs-comment">/** 
 * @brief &#x5C06;&#x56FE;&#x7247;&#x6570;&#x636E;&#x4E0A;&#x4F20;&#x5230;GPU;
 * @param target    &#x76EE;&#x6807;&#x7EB9;&#x7406;&#xFF0C;GL_TEXTURE_2D(2D&#x7EB9;&#x7406;)
 * @param level     &#x5F53;&#x56FE;&#x7247;&#x6570;&#x636E;&#x662F;&#x5305;&#x542B;&#x591A;&#x4E2A;mipmap&#x5C42;&#x7EA7;&#x65F6;&#xFF0C;&#x6307;&#x5B9A;&#x4F7F;&#x7528;mipmap&#x5C42;&#x7EA7;&#x3002;
 * @param internalformat &#x56FE;&#x7247;&#x6570;&#x636E;&#x4E0A;&#x4F20;&#x5230;GPU&#x540E;&#xFF0C;&#x5728;&#x663E;&#x5B58;&#x4E2D;&#x4FDD;&#x5B58;&#x4E3A;&#x54EA;&#x79CD;&#x683C;&#x5F0F;&#xFF1F;
 * @param width
 * @param height
 * @param border
 * @param format &#x4E0A;&#x4F20;&#x7684;&#x56FE;&#x7247;&#x6570;&#x636E;&#x683C;&#x5F0F;&#xFF0C;RGB&#x3001;RGBA&#x3001;Alpha&#x7B49;
 * @param type &#x56FE;&#x7247;&#x6570;&#x636E;&#x53D8;&#x91CF;&#x683C;&#x5F0F;&#xFF0C;&#x4E00;&#x822C;&#x90FD;&#x662F;GL_UNSIGNED_BYTE(0-255&#x8303;&#x56F4;)
 * @param pixels &#x56FE;&#x7247;&#x6570;&#x636E;
 * @return
 */</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">glTexImage2D</span><span class="hljs-params">(GLenum   target, GLint   level, GLint   internalformat, GLsizei   width, GLsizei   height, GLint   border, GLenum   format, GLenum   type, <span class="hljs-keyword">const</span> <span class="hljs-keyword">void</span> * pixels)</span></span>;
</code></pre>
<p>&#x6CE8;&#x610F; <code>internalformat</code> &#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x3002;
&#x56FE;&#x7247;&#x6570;&#x636E;&#x4E0A;&#x4F20;&#x5230;&#x5230;GPU&#x540E;&#xFF0C;&#x53EF;&#x4EE5;&#x9009;&#x62E9;&#x4FDD;&#x5B58;&#x7684;&#x683C;&#x5F0F;&#x3002;
&#x800C;&#x6211;&#x4EEC;&#x8FD9;&#x4E00;&#x7AE0;&#x7684;&#x4E3B;&#x9898;&#x662F;<code>&#x538B;&#x7F29;&#x7EB9;&#x7406;</code>&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x8981;&#x8BB2;&#x7684;&#x5C31;&#x662F;&#xFF0C;&#x53EF;&#x4EE5;&#x4FDD;&#x5B58;&#x4E3A;&#x538B;&#x7F29;&#x683C;&#x5F0F;&#x3002;</p>
<h3 id="1-&#x4E3A;&#x4EC0;&#x4E48;&#x4F7F;&#x7528;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#xFF1F;"><a name="1-&#x4E3A;&#x4EC0;&#x4E48;&#x4F7F;&#x7528;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#xFF1F;" class="anchor-navigation-ex-anchor" href="#1-&#x4E3A;&#x4EC0;&#x4E48;&#x4F7F;&#x7528;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#xFF1F;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x4E3A;&#x4EC0;&#x4E48;&#x4F7F;&#x7528;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#xFF1F;</h3>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#x56FE;&#x7247;&#x5BFC;&#x5165;Unity&#x4E4B;&#x540E;&#xFF0C;&#x9ED8;&#x8BA4;&#x4F1A;&#x8BBE;&#x7F6E;&#x4E3A;&#x538B;&#x7F29;&#x683C;&#x5F0F;&#xFF1F;
&#x5728;<code>glTexImage2D</code>&#x8FD9;&#x4E2A;&#x63A5;&#x53E3;&#x91CC;&#x9762;&#xFF0C;&#x8BBE;&#x7F6E;&#x56FE;&#x7247;&#x6570;&#x636E;&#x4FDD;&#x5B58;&#x4E3A;&#x538B;&#x7F29;&#x683C;&#x5F0F;&#x540E;&#xFF0C;&#x4F1A;&#x6709;&#x4EC0;&#x4E48;&#x597D;&#x5904;&#xFF1F;</p>
<p>&#x7B54;&#x6848;&#x5C31;&#x662F;&#xFF1A;<font color="blue">&#x8282;&#x7701;&#x663E;&#x5B58;</font>&#x3002;</p>
<p>&#x5982;&#x4ECA;&#x7684;3A&#x5927;&#x4F5C;&#xFF0C;&#x5404;&#x79CD;4K&#x8D34;&#x56FE;&#x3001;&#x8D85;&#x9AD8;&#x7CBE;&#x5EA6;&#x6A21;&#x578B;&#xFF0C;&#x4E00;&#x4E2A;&#x573A;&#x666F;&#x6570;&#x636E;&#x91CF;&#x51E0;G&#xFF0C;&#x8FD9;&#x4E9B;&#x6570;&#x636E;&#x90FD;&#x662F;&#x8981;&#x4E0A;&#x4F20;&#x5230;&#x663E;&#x5B58;&#x7684;&#xFF0C;&#x4E3A;&#x4E86;&#x8BA9;&#x6E38;&#x620F;&#x9002;&#x914D;&#x66F4;&#x591A;&#x7684;&#x786C;&#x4EF6;&#xFF0C;&#x5F00;&#x53D1;&#x8005;&#x4EEC;&#x4E5F;&#x662F;&#x5404;&#x663E;&#x795E;&#x901A;&#xFF0C;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#x5C31;&#x662F;OpenGL&#x5B98;&#x65B9;&#x63D0;&#x4F9B;&#x7684;&#x4E00;&#x79CD;&#x624B;&#x6BB5;&#x3002;</p>
<h3 id="2-&#x4F7F;&#x7528;&#x538B;&#x7F29;&#x7EB9;&#x7406;"><a name="2-&#x4F7F;&#x7528;&#x538B;&#x7F29;&#x7EB9;&#x7406;" class="anchor-navigation-ex-anchor" href="#2-&#x4F7F;&#x7528;&#x538B;&#x7F29;&#x7EB9;&#x7406;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x4F7F;&#x7528;&#x538B;&#x7F29;&#x7EB9;&#x7406;</h3>
<p>OpenGL&#x652F;&#x6301;&#x7684;&#x7EB9;&#x7406;&#x6570;&#x636E;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<table>
<tbody><tr bgcolor="AliceBlue"><td><b>&#x7EB9;&#x7406;&#x683C;&#x5F0F;</b></td><td><b>&#x538B;&#x7F29;&#x7EB9;&#x7406;&#x683C;&#x5F0F;</b></td></tr>
<tr><td>GL_ALPHA</td><td>GL_COMPRESSED_ALPHA</td></tr>
<tr><td>GL_LUMINANCE</td><td>GL_COMPRESSED_LUMINANCE</td></tr>
<tr><td>GL_LUMINANCE_ALPHA</td><td>GL_COMPRESSED_LUMINANCE_ALPHA</td></tr>
<tr><td>GL_RGB</td><td>GL_COMPRESSED_RGB</td></tr>
<tr><td>GL_RGBA</td><td>GL_COMPRESSED_RGBA</td></tr>
<tr><td>GL_INTENSITY</td><td>GL_COMPRESSED_INTENSITY</td></tr>
</tbody></table>


<p>&#x4E4B;&#x524D;<code>glTexImage2D</code>&#x8FD9;&#x4E2A;&#x63A5;&#x53E3;&#x7684; <code>internalformat</code> &#x53C2;&#x6570;&#x503C;&#x662F;<code>GL_RGB</code>&#xFF0C;&#x73B0;&#x5728;&#x53EA;&#x8981;&#x8BBE;&#x7F6E;&#x4E3A;&#x5BF9;&#x5E94;&#x7684;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#x683C;&#x5F0F;<code>GL_COMPRESSED_RGB</code>&#x5373;&#x53EF;&#x3002;</p>
<pre><code class="lang-c++"><span class="hljs-comment">//3. &#x5C06;&#x56FE;&#x7247;rgb&#x6570;&#x636E;&#x4E0A;&#x4F20;&#x5230;GPU;&#x5E76;&#x8FDB;&#x884C;&#x538B;&#x7F29;&#x3002;</span>
glTexImage2D(GL_TEXTURE_2D, <span class="hljs-number">0</span>, GL_COMPRESSED_RGB, texture2d-&gt;width_, texture2d-&gt;height_, <span class="hljs-number">0</span>, texture2d-&gt;gl_texture_format_, GL_UNSIGNED_BYTE, data);
</code></pre>
<h3 id="3-&#x67E5;&#x770B;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#x6548;&#x679C;"><a name="3-&#x67E5;&#x770B;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#x6548;&#x679C;" class="anchor-navigation-ex-anchor" href="#3-&#x67E5;&#x770B;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#x6548;&#x679C;"><i class="fa fa-link" aria-hidden="true"></i></a>3. &#x67E5;&#x770B;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#x6548;&#x679C;</h3>
<p>&#x4EE3;&#x7801;&#x7F16;&#x8BD1;&#x8FD0;&#x884C;&#x540E;&#xFF0C;&#x6B63;&#x5E38;&#x7ED8;&#x5236;&#x4E86;&#x7ACB;&#x65B9;&#x4F53;&#xFF0C;&#x4F46;&#x662F;&#x600E;&#x4E48;&#x6837;&#x786E;&#x8BA4;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#x7684;&#x6548;&#x679C;&#x5462;&#xFF0C;&#x5C31;&#x662F;&#x8BF4;&#x600E;&#x4E48;&#x6837;&#x786E;&#x8BA4;&#x663E;&#x5B58;&#x5360;&#x7528;&#x964D;&#x4F4E;&#xFF1F;
&#x8FD9;&#x91CC;&#x501F;&#x52A9;GPU&#x72B6;&#x6001;&#x5DE5;&#x5177; - <code>GPU-Z</code> &#x6765;&#x67E5;&#x770B;&#x5B9E;&#x65F6;&#x663E;&#x5B58;&#x3002;</p>
<p>&#x4F7F;&#x7528;&#x672A;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#xFF0C;<code>glTexImage2D</code>&#x63A5;&#x53E3;&#x8C03;&#x7528;&#x524D;&#x540E;&#x663E;&#x5B58;&#x5BF9;&#x6BD4;&#x5982;&#x4E0B;&#xFF1A;
<a href="../../imgs/texture_make_beautiful/draw_cube_texture_compress/rgb_memory.gif" data-lightbox="3be56df0-7a84-41e0-8b57-bbd1912feb6f" data-title=""><img src="../../imgs/texture_make_beautiful/draw_cube_texture_compress/rgb_memory.gif" alt=""></a></p>
<p>&#x4ECE;52m &#x53D8;&#x52A8;&#x5230; 116m&#xFF0C;&#x4F7F;&#x7528;&#x4E86;&#x7EA6; 64m &#x663E;&#x5B58;&#x3002;</p>
<p>&#x4F7F;&#x7528;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#xFF0C;&#x63A5;&#x53E3;&#x8C03;&#x7528;&#x524D;&#x540E;&#x663E;&#x5B58;&#x5BF9;&#x6BD4;&#x5982;&#x4E0B;&#xFF1A;
<a href="../../imgs/texture_make_beautiful/draw_cube_texture_compress/rgb_compress_memory.gif" data-lightbox="23a75fcf-65e3-4e22-bce4-ad440c4e8147" data-title=""><img src="../../imgs/texture_make_beautiful/draw_cube_texture_compress/rgb_compress_memory.gif" alt=""></a></p>
<p>&#x4ECE;52m &#x53D8;&#x52A8;&#x5230; 60m&#xFF0C;&#x4F7F;&#x7528;&#x4E86;&#x7EA6; 8m &#x663E;&#x5B58;&#x3002;</p>
<p>&#x6548;&#x679C;&#x5F88;&#x660E;&#x663E;&#xFF0C;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#x540E;&#xFF0C;&#x5360;&#x7528;&#x7684;&#x663E;&#x5B58;&#x662F;&#x539F;&#x6765;&#x7684; 1/6 &#x5DE6;&#x53F3;&#x3002;</p>
<p>&#x5BF9;&#x6BD4;Unity&#x4E2D;&#x538B;&#x7F29;&#x540E;&#x7684;&#x6548;&#x679C;&#xFF0C;&#x5DEE;&#x5F02;&#x4E0D;&#x5927;&#x3002;
<a href="../../imgs/texture_make_beautiful/draw_cube_texture_compress/unity_compress_size.jpg" data-lightbox="c18f2115-849d-443d-927d-0cc65eb6d11a" data-title=""><img src="../../imgs/texture_make_beautiful/draw_cube_texture_compress/unity_compress_size.jpg" alt=""></a></p>
<h3 id="4-&#x95EE;&#x9898;&#x4E0E;&#x4F18;&#x5316;"><a name="4-&#x95EE;&#x9898;&#x4E0E;&#x4F18;&#x5316;" class="anchor-navigation-ex-anchor" href="#4-&#x95EE;&#x9898;&#x4E0E;&#x4F18;&#x5316;"><i class="fa fa-link" aria-hidden="true"></i></a>4. &#x95EE;&#x9898;&#x4E0E;&#x4F18;&#x5316;</h3>
<p>&#x542F;&#x52A8;&#x65F6;&#x6709;&#x4E00;&#x6BB5;&#x65F6;&#x95F4;&#x7684;&#x767D;&#x5C4F;&#xFF0C;&#x65AD;&#x70B9;&#x8C03;&#x8BD5;&#x53D1;&#x73B0;<code>stbi_load</code> &#x548C; <code>glTexImage2D</code>&#x8017;&#x65F6;&#x8F83;&#x957F;&#xFF0C;&#x8FD9;&#x91CC;&#x5F15;&#x5165;<code>stopwatch</code>&#x5DE5;&#x5177;&#x7C7B;&#x6765;&#x8FDB;&#x884C;&#x6D4B;&#x91CF;&#x3002;</p>
<pre><code class="lang-c++">Texture2D* Texture2D::LoadFromFile(<span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span>&amp; image_file_path)
{
    ......
    StopWatch stopwatch;
    stopwatch.start();
    <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">char</span>* data = stbi_load(image_file_path.c_str(), &amp;(texture2d-&gt;width_), &amp;(texture2d-&gt;height_), &amp;channels_in_file, <span class="hljs-number">0</span>);
    stopwatch.stop();
    <span class="hljs-built_in">std</span>::<span class="hljs-keyword">int64_t</span> decompress_jpg_cost = stopwatch.milliseconds();
    ......

    stopwatch.restart();
    <span class="hljs-comment">//3. &#x5C06;&#x56FE;&#x7247;rgb&#x6570;&#x636E;&#x4E0A;&#x4F20;&#x5230;GPU;&#x5E76;&#x8FDB;&#x884C;&#x538B;&#x7F29;&#x3002;</span>
    glTexImage2D(GL_TEXTURE_2D, <span class="hljs-number">0</span>, GL_COMPRESSED_RGB, texture2d-&gt;width_, texture2d-&gt;height_, <span class="hljs-number">0</span>, texture2d-&gt;gl_texture_format_, GL_UNSIGNED_BYTE, data);
    stopwatch.stop();
    <span class="hljs-built_in">std</span>::<span class="hljs-keyword">int64_t</span> upload_and_compress_cost = stopwatch.milliseconds();
    ......
}
</code></pre>
<p>&#x8017;&#x65F6;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#xFF1A;
<a href="../../imgs/texture_make_beautiful/draw_cube_texture_compress/jpg_cost.jpg" data-lightbox="1cc8ed94-a172-4cdf-920b-3a3463c3ae55" data-title=""><img src="../../imgs/texture_make_beautiful/draw_cube_texture_compress/jpg_cost.jpg" alt=""></a></p>
<p>&#x4ECE;&#x786C;&#x76D8;&#x52A0;&#x8F7D;jpg&#x5E76;&#x89E3;&#x6790;&#x5F97;&#x5230;RGB&#x6570;&#x636E;&#xFF1A;1571 ms
&#x4E0A;&#x4F20;RGB&#x6570;&#x636E;&#x5230;GPU&#x5E76;&#x538B;&#x7F29;&#xFF1A;960 ms</p>
<p>&#x8FD9;&#x53EA;&#x662F;&#x4E00;&#x5F20;4096&#x7684;&#x56FE;&#x7247;&#xFF0C;&#x5C31;&#x82B1;&#x8D39;&#x4E86;2.5s&#x7684;&#x65F6;&#x95F4;&#xFF0C;&#x6211;&#x4EEC;&#x5FC5;&#x987B;&#x60F3;&#x529E;&#x6CD5;&#x4F18;&#x5316;&#x3002;</p>
<p>&#x5236;&#x5B9A;&#x4F18;&#x5316;&#x65B9;&#x6848;&#x4E4B;&#x524D;&#xFF0C;&#x5148;&#x7406;&#x6E05;&#x695A;&#x4E3A;&#x4EC0;&#x4E48;&#x8FD9;&#x4E48;&#x6162;&#xFF0C;&#x4E3B;&#x8981;&#x662F;3&#x4E2A;&#x539F;&#x56E0;&#xFF1A;</p>
<ol>
<li>&#x89E3;&#x6790;jpg&#x6162;&#xFF1A;jpg&#x662F;&#x4E00;&#x79CD;&#x538B;&#x7F29;&#x56FE;&#x7247;&#x6587;&#x4EF6;&#xFF0C;&#x9700;&#x8981;&#x89E3;&#x538B;&#x624D;&#x53EF;&#x4EE5;&#x5F97;&#x5230;&#x672A;&#x538B;&#x7F29;&#x7684;RGB&#x6570;&#x636E;&#xFF0C;&#x89E3;&#x538B;&#x662F;&#x5F88;&#x6162;&#x7684;&#x4E00;&#x4E2A;&#x8FC7;&#x7A0B;&#x3002;</li>
<li>&#x4E0A;&#x4F20;&#x6162;&#xFF1A;4096&#x7684;&#x56FE;&#x7247;&#xFF0C;&#x672A;&#x538B;&#x7F29;&#x7684;RGB&#x6570;&#x636E;&#x5927;&#x5C0F;&#x662F;48MB&#xFF0C;&#x4E0A;&#x4F20;&#x8981;&#x8017;&#x8D39;&#x4E00;&#x5B9A;&#x65F6;&#x95F4;&#x3002;</li>
<li>&#x538B;&#x7F29;&#x6162;&#xFF1A;&#x6570;&#x636E;&#x4E0A;&#x4F20;&#x540E;&#xFF0C;GPU&#x5BF9;RGB&#x6570;&#x636E;&#x8FDB;&#x884C;&#x538B;&#x7F29;&#x5B58;&#x50A8;&#xFF0C;&#x538B;&#x7F29;&#x9700;&#x8981;&#x8017;&#x8D39;&#x65F6;&#x95F4;&#x3002;</li>
</ol>
<p>&#x5BF9;&#x5E94;&#x7684;&#x89E3;&#x51B3;&#x529E;&#x6CD5;&#x5C31;&#x662F;&#xFF1A;<font color="blue">&#x4F7F;&#x7528;GPU&#x652F;&#x6301;&#x7684;&#x538B;&#x7F29;&#x7EB9;&#x7406;&#x6570;&#x636E;&#x683C;&#x5F0F;</font>&#x3002;</p>
<p>&#x5177;&#x4F53;&#x505A;&#x6CD5;&#x5C31;&#x662F;&#xFF1A;&#x5C06;GPU&#x4E2D;&#x538B;&#x7F29;&#x597D;&#x7684;&#x7EB9;&#x7406;&#x6570;&#x636E;&#xFF0C;&#x4FDD;&#x5B58;&#x5230;&#x786C;&#x76D8;&#x4F5C;&#x4E3A;&#x56FE;&#x7247;&#x6587;&#x4EF6;&#x3002;</p>
<p>&#x5E26;&#x6765;&#x7684;&#x597D;&#x5904;&#x662F;&#xFF1A;</p>
<ol>
<li>&#x65E0;&#x9700;&#x89E3;&#x6790;&#xFF0C;&#x76F4;&#x63A5;&#x4E0A;&#x4F20;GPU&#x3002;</li>
<li>&#x6570;&#x636E;&#x5DF2;&#x7ECF;&#x538B;&#x7F29;&#xFF0C;&#x4E0A;&#x4F20;&#x6570;&#x636E;&#x91CF;&#x5C0F;&#x3002;</li>
<li>&#x6570;&#x636E;&#x5DF2;&#x7ECF;&#x538B;&#x7F29;&#xFF0C;&#x4E0A;&#x4F20;&#x4E4B;&#x540E;&#x65E0;&#x9700;&#x518D;&#x6B21;&#x538B;&#x7F29;&#x3002;</li>
</ol>
<p>OpenGL&#x63D0;&#x4F9B;&#x4E86;&#x63A5;&#x53E3;<code>glGetCompressedTexImage</code>&#xFF0C;&#x5C06;GPU&#x4E2D;&#x538B;&#x7F29;&#x597D;&#x7684;&#x7EB9;&#x7406;&#x6570;&#x636E;&#xFF0C;&#x4ECE;&#x663E;&#x5B58;&#x4E0B;&#x8F7D;&#x5230;&#x5185;&#x5B58;&#xFF0C;&#x4E0B;&#x4E00;&#x8282;&#x5C06;&#x5236;&#x4F5C;&#x4E00;&#x4E2A;&#x5DE5;&#x5177;&#xFF0C;&#x5BF9;<code>.jpg</code>&#x3001;<code>.png</code> &#x56FE;&#x7247;&#x8FDB;&#x884C;&#x6279;&#x91CF;&#x5904;&#x7406;&#x3002; </p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; captainchen all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">File Modify: 
2021-04-19 11:27:54
</span></footer></body></html>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="5.5 绘制带贴图的立方体盒子.html" class="navigation navigation-prev " aria-label="Previous page: 5.5 绘制带贴图的立方体盒子">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="5.7 图片压缩工具.html" class="navigation navigation-next " aria-label="Next page: 5.7 图片压缩工具">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"5.6 压缩纹理","level":"2.6.6","depth":2,"next":{"title":"5.7 图片压缩工具","level":"2.6.7","depth":2,"path":"pages/5. 绘制贴图/5.7 图片压缩工具.md","ref":"pages/5. 绘制贴图/5.7 图片压缩工具.md","articles":[]},"previous":{"title":"5.5 绘制带贴图的立方体盒子","level":"2.6.5","depth":2,"path":"pages/5. 绘制贴图/5.5 绘制带贴图的立方体盒子.md","ref":"pages/5. 绘制贴图/5.5 绘制带贴图的立方体盒子.md","articles":[]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","tbfed-pagefooter","splitter","lightbox","anchor-navigation-ex","search-pro","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy captainchen","modify_format":"YYYY-MM-DD HH:mm:ss"},"livereload":{},"splitter":{},"search-pro":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":false,"showLevel":false},"lightbox":{"jquery":true,"sameUuid":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"captainchen","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"游戏引擎浅入浅出","gitbook":"*"},"file":{"path":"pages/5. 绘制贴图/5.6 压缩纹理.md","mtime":"2021-04-19T03:27:54.754Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-04-30T15:25:09.576Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lightbox/js/lightbox.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

